package com.ruoyi.content.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.content.domain.SinglePage;
import com.ruoyi.content.service.ISinglePageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 单页面列表Controller
 * 
 * @author ruoyi
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/single")
public class SinglePageController extends BaseController
{
    @Autowired
    private ISinglePageService singlePageService;

    /**
     * 查询单页面列表列表
     */
    @RequiresPermissions("content:single:list")
    @GetMapping("/list")
    public TableDataInfo list(SinglePage singlePage)
    {
        startPage();
        List<SinglePage> list = singlePageService.selectSinglePageList(singlePage);
        return getDataTable(list);
    }

    /**
     * 导出单页面列表列表
     */
    @RequiresPermissions("content:single:export")
    @Log(title = "单页面列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SinglePage singlePage)
    {
        List<SinglePage> list = singlePageService.selectSinglePageList(singlePage);
        ExcelUtil<SinglePage> util = new ExcelUtil<SinglePage>(SinglePage.class);
        util.exportExcel(response, list, "单页面列表数据");
    }

    /**
     * 获取单页面列表详细信息
     */
    @RequiresPermissions("content:single:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(singlePageService.selectSinglePageById(id));
    }

    /**
     * 新增单页面列表
     */
    @RequiresPermissions("content:single:add")
    @Log(title = "单页面列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SinglePage singlePage)
    {
        return toAjax(singlePageService.insertSinglePage(singlePage));
    }

    /**
     * 修改单页面列表
     */
    @RequiresPermissions("content:single:edit")
    @Log(title = "单页面列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SinglePage singlePage)
    {
        return toAjax(singlePageService.updateSinglePage(singlePage));
    }

    /**
     * 删除单页面列表
     */
    @RequiresPermissions("content:single:remove")
    @Log(title = "单页面列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(singlePageService.deleteSinglePageByIds(ids));
    }
}
